package co.unipiloto.identify;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;

import co.unipiloto.identify.camera.CameraControl;
import co.unipiloto.identify.camera.CameraView;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class Main extends Activity  implements OnClickListener{
	
	private TextView txtExplination;
	private Button btnIdentify;
	
	private static int TAKE_PICTURE = 1;
	private Uri outputFileUri;
	private OutputStream filoutputStream;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        txtExplination = (TextView) findViewById(R.id.idExplination);  
      btnIdentify = (Button) findViewById(R.id.idBtnIdentify);    
      btnIdentify.setOnClickListener(this); 
        
    }

	@Override
	public void onClick(View v) {
		saveFullImage();
		
	}
 	private void saveFullImage() {
    	Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    	File file = new File(Environment.getExternalStorageDirectory(),
    	"captureInfo.jpg");
    	
    	try {
			file.createNewFile();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	outputFileUri = Uri.fromFile(file);
    	intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
    	startActivityForResult(intent, TAKE_PICTURE);
    	}
 	
 	@Override
	protected void onActivityResult(int requestCode,
	int resultCode, Intent data) {
		if (requestCode == TAKE_PICTURE) {
		Uri imageUri = null;
		// Check if the result includes a thumbnail Bitmap
		if (data != null) {
		if (data.hasExtra("data")) {
		Bitmap thumbnail = data.getParcelableExtra("data");
		// TODO Do something with the thumbnail
		}
		}
		else {
	//		filoutputStream=new OutputStream();
		// TODO Do something with the full image stored
		// in outputFileUri
		}
		}
		String str=new String("Identificando......");
		  Toast.makeText(getBaseContext(), str, 
	       		Toast.LENGTH_LONG).show();
		  
		  callCameraControl();
	}
 	private void callCameraControl() {
		Intent myIntent = new Intent(this,CameraView.class);
//	Intent myIntent = new Intent(this, CameraView.class);
	startActivity(myIntent);

	}
}